//
//  HelloWorldLayer.h
//  demo_3
//
//  Created by mac on 12-2-20.
//  Copyright __MyCompanyName__ 2012年. All rights reserved.
//


// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
#import "NGSScoreListBoard.h"
#import "commons.h"

//tag macro definition for all the items in this layer
#define BOWL_TAG 1
#define FLY_FLOUR_TAG 2
#define COUNT_TAG 3

//bowl move macro definitions
#define BOWL_MOVE_DURATION 1

////yuda defined macro variables

#define FLOUR_WIDTH 372
#define FLOUR_HEIHT 462
#define BEEF_WIDTH 334
#define BEEF_HEIHT 400
#define MUTTON_WIDTH 334
#define MUTTON_HEIHT 402
#define FLYFLOUR_WIDTH 70
#define FLYFLOUR_HEIHT 172

#define FLYBEEF_WIDTH 70
#define FLYBEEF_HEIHT 172
#define FLYRADISH_WIDTH 70
#define FLYRADISH_HEIHT 172
#define FLYCUCUMBER_WIDTH 70
#define FLYCUCUMBER_HEIHT 172
#define FLYMUTTON_WIDTH 70
#define FLYMUTTON_HEIHT 172

#define CUCUMBER_WIDTH 168
#define CUCUMBER_HEIHT 476
#define RADISH_WIDTH 330
#define RADISH_HEIHT 484
#define KNIFE_WIDTH 70
#define KNIFE_HEIHT 172
#define MAX_FOOD_INDEX 2
#define TIMETODES 0.3
#define FOOD_Y_BOTTOM 30
#define FOOD_Y_LOW 60
#define FOOD_Y_HIGH 90
#define NUMBER_X 160
#define NUMBER_Y 380

//scales
#define BEEF_SCALE 0.45
#define MUTTON_SCALE 0.45
#define FLOUR_SCALE 0.4
#define FLYFLOUR_SCALE 0.4
#define CUCUMBER_SCALE 0.45
#define RADISH_SCALE 0.45
#define BACKGROUND_SPRITE_SACLE 0.5

//
#define TIMETOFLY 0.6
//index

// HelloWorldLayer
@interface HelloWorldLayer : CCLayerColor {
    //some public used variables
    //will be initialized in initExtension method by @cc
    int SCREEN_WIDTH;
    int SCREEN_HEIGHT;
    int currentScore;
    
    //variables defined by @cc
    BowlOfNooldModelLayer *midBowl;
    BowlOfNooldModelLayer *leftBowl;
    BowlOfNooldModelLayer *rightBowl;
    BowlOfNooldModelLayer *hiddenBowl;
    /*
    CCSprite *midBowl;
    CCSprite *leftBowl;
    CCSprite *rightBowl;
    CCSprite *hiddenBowl;
    */
     
    CCLayer *backGroundLayer;
    CCLayer *scoreListBoardLayer;
    
    //variables defined by @zhanpeng
    NSMutableArray *_targets;
    NSMutableArray *_projectiles;
    NSMutableArray *_number;
    NSMutableArray *_flySlices;
    CGPoint _points[9];
    //NSMutableArray *_foods;
    
    int _projectilesDestroyed;
    int _numberOfFlour;
    int areaIndex;
    int foodIndex;
    int distance_betweenFood;
    int foodInMiddle;
    float offset;
    float distance;
    float h_beef;
    float h_flour;
    float h_mutton;
    float h_radish;
    float h_cucumber;
    float x1;
    float x2;
    float x3;
    float x4;
    float x5;
    
    CGRect flourRect;
    CGRect beefRect;
    CGRect muttonRect;
    CGRect middle_area;
    CGRect flyFlourRect;
    bool inside;
    bool oneSlice;
    bool cute;
    bool draw;
    CGPoint temp;
    CGPoint temp_1;
    CGPoint temp_2;
    CGPoint temp_4;
    CGPoint realDest;//the destination of flyflour
    CGSize winSize;
    CGPoint leftPoint;
    CGPoint rightPoint;
    CGPoint middlePoint;
    CGPoint rightPoint_2;
    CGPoint leftPoint_2;
    CGPoint rightPoint_3;
    CGPoint leftPoint_3;
    CGPoint rightPoint_4;
    CGPoint leftPoint_4;
    CGPoint beefPoint;
    CGPoint radishPoint;
    CGPoint flourPoint;
    CGPoint cucumberPoint;
    CGPoint muttonPoint;
    
    CGPoint forBeef;
    CGPoint forFlour;
    CGPoint forMutton;
    
    //flying slice direction
    CGPoint directionStartPoint;
    CGPoint directionEndPoint;
    
    CCSprite *knife;
    //CCSprite *Beef_l;
    CCSprite *Beef;
    CCSprite *flour;
    CCSprite *Mutton;
    CCSprite *Radish;
    CCSprite *Cucumber;
    CCSprite *flyBeef;
    CCSprite *flyRadish;
    CCSprite *flyFlour;
    CCSprite *flyCucumber;
    CCSprite *flyMutton;
    
    //////////////////////////
    int sumScore;
    int numberOfBeefNoodle;
    int numberOfMuttonNoodle;
    
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
//create the sprites of 01~10
-(void)setNumber;
//initial the layer
-(id) init;
//
-(void) registerWithTouchDispatcher;
//
-(void)gameLogic:(ccTime)dt;
//when the touch operation happen it calls for this function
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
//when you touch the device and move it calls for this function
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
//when your move finish and your finger leave behind the device it calls for the function
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event;
//
-(CGPoint) locationFromTouch:(UITouch*)touch;
//judge weather one point is in one rectangle
-(CGRect)AtlasRect:(CCSprite *)atlSpr;
//judge weather one point is in the area of flour
-(bool)inOrOut:(CGPoint)p_1;
//show the picture of number
-(void)showNumber:(int)num;
//add the sprite flour onto the layer
-(void)addFlour;
//add the sprite knife onto the layer
-(void)addKnife;
//add the sprite beef onto the layer
-(void)addBeef;
//add the sprite mutton onto the layer
-(void)addMutton;
//add the sprite cucumber onto the layer
-(void)addCucumber;
//add the sprite radish onto the layer
-(void)addRadish;
//add the score list board layer
-(void)addScoreListBoard;
//move the rects
-(void) moveRect:(CGPoint)a :(CGPoint)b :(CGPoint)c;
//load the music
-(void)loadBgMusic;
//play the music
-(void)playBgMusic:(NSString*)fileName;
//for a x calculate the y during touchmove
-(float)getCoordinate_y:(float)x;
//get all five x of the sprite during the touchmove
-(void)getAll_x:(int)index;
//set the position of each sprite using the x,y during the touchmove
-(void)moveSprites;
//set the position points
-(void)setPoints;
//find the nearest point of the touchEnd point
-(int)theNearestPoint:(CGPoint)p;
//set the final location of the five sprites
-(void)finalLocation:(int)index :(CGPoint)p;
//move the five sprites to their location
-(void)moveToTheFinalLocation;
//create a slice and fly to the destination
-(void)flyOneSlice:(int)index:(CGPoint)p;
//add the fly beef
-(void)addFlyBeef:(CGPoint)p;
//add the fly radish
-(void)addFlyRadish:(CGPoint)p;
//add the fly flour
-(void)addFlyFlour:(CGPoint)p;
//add the fly cucumber
-(void)addFlyCucumber:(CGPoint)p;
//add the fly mutton
-(void)addFlyMutton:(CGPoint)p;
//
-(int)foodInMiddle:(CGFloat)p_x;
@end

@interface HelloWorldLayer(Extension)

-(void) addBowl;
-(void) bowlMoveActionCallback;
-(void) initExtension;
-(void) switchBowl;
-(void) printBowlPosition:(BOOL) boa;
-(CGRect) getBowlHitRect;
-(void) addBackgoundLayer;

-(void) bezierTo:(CCSprite *)mSprite direction:(CGPoint)direction durTime:(float)time callback:(CCAction *)callbackAction;
-(CGPoint) getBezierToDestByDirection:(CGPoint)direction fromPosition:(CGPoint)pos;
@end
